package com.neuedu.helloworld.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class MusicService extends Service {

    private boolean running = false;


    public MusicService() {
    }


    @Override
    public void onCreate() {
        super.onCreate();
        running = true;
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        //启动后台运行的程序
        String url = intent.getStringExtra("music");

        new Thread(){
            @Override
            public void run() {
                super.run();

                while (running){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Log.d("Service","线程在运行(模拟音乐播放器)"+System.currentTimeMillis()+" mp3地址:"+url);
                }
            }
        }.start();

        return super.onStartCommand(intent, flags, startId);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();

        running = false;
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }




}